package com.sugon.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.RandomUtil;
import com.sugon.dao.InspectionInstitutionDao;
import com.sugon.entity.InspectionInstitutionEntity;
import com.sugon.service.InspectionInstitutionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 特种设备检测机构Service实现类
 *
 * @author YuXD
 * @date 2021-09-08
 */
@Service("inspectionInstitutionService")
public class InspectionInstitutionServiceImpl implements InspectionInstitutionService {

    @Autowired
    private InspectionInstitutionDao inspectionInstitutionDao;

    @Override
    public InspectionInstitutionEntity queryObjectByName(String name) {
        Map<String, Object> queryParam = MapUtil.newHashMap();
        queryParam.put("name", name);
        List<InspectionInstitutionEntity> unitList = queryList(queryParam);
        return CollectionUtil.isNotEmpty(unitList) ? unitList.get(0) : null;
    }

    @Override
    public InspectionInstitutionEntity queryObject(String id) {
        return inspectionInstitutionDao.queryObject(id);
    }

    @Override
    public List<InspectionInstitutionEntity> queryList(Map<String, Object> map) {
        return inspectionInstitutionDao.queryList(map);
    }

    @Override
    public int queryTotal(Map<String, Object> map) {
        return inspectionInstitutionDao.queryTotal(map);
    }

    @Override
    public int save(InspectionInstitutionEntity inspectionInstitution) {
        inspectionInstitution.setId(RandomUtil.randomString(32));
        inspectionInstitution.setCreateTime(DateUtil.date());
        return inspectionInstitutionDao.save(inspectionInstitution);
    }

    @Override
    public int update(InspectionInstitutionEntity inspectionInstitution) {
        inspectionInstitution.setUpdateTime(DateUtil.date());
        return inspectionInstitutionDao.update(inspectionInstitution);
    }

    @Override
    public int delete(String id) {
        return inspectionInstitutionDao.delete(id);
    }

    @Override
    public int deleteBatch(String[] ids) {
        return inspectionInstitutionDao.deleteBatch(ids);
    }
}
